//app.js
require('lib/es6-promise.min.js').polyfill();
import LOGIN from '/API/LOGIN'
import hudClass from "/lib/hud/hud";
App({
  onLaunch: function () {
    //本地获取GUID
    var that=this
    that.globalData.guid = wx.getStorageSync('guid')       
    that.globalData.token = wx.getStorageSync('token') 
    console.log('guid:' + that.globalData.guid)  
    if (that.globalData.guid == null || that.globalData.guid || that.globalData.guid == undefined || that.globalData.guid.length==0)
    {
      
      LOGIN.GetGuid().then(function (d) {
        if (d!=undefined)
        {
          wx.setStorageSync('guid', d.data)
          that.globalData.guid = d.data
        }        
      })
      
    }
    
  },
  hudClass: (s) => new hudClass(s),
  getUserInfo:function(cb){
    var that = this
    if(this.globalData.userInfo){
      typeof cb == "function" && cb(this.globalData.userInfo)
    }else{
      //调用登录接口
      wx.login({
        success: function () {
          wx.getUserInfo({
            success: function (res) {
              console.log(res)
              that.globalData.userInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })
    }
  },
  globalData:{
    userInfo:null,
    guid:null,
    token:null,
    departmentdetailid:null,
    role:'admin'
  }
})
